﻿@model IList<Inovout.Kuajing.Models.ShipmentOrder>
@{
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
@section styles {
    <style>
      
    </style>
}

@section scriptsHead {
    <script>

        $(document).ready(function () {
            $("#uploadFile").on("change", function () {

                var fileName = $(this).val();
                if (fileName.toLowerCase().indexOf(".csv") != -1) {
                    debugger;
                    $("#fileForm").submit();
                } else {
                    alert("格式不正确");
                    return;
                }
            })

            $("#uploadlogisticsInfo").on("click", function () {
                var orderList = [];
                var is_up = false;
                $("#tb_contact > tbody").find("tr").each(function (index, item) {
                    var orderNo = $(this).find("td").eq(0).text();
                    var logisticsOrderNo = $(item).find("td").eq(1).text();
                    var logisticsName = $(item).find("td").eq(2).text();
                    var logisticsCode = $(item).find("td").eq(3).text();
                    var status = $(item).find("td").eq(4).text();
                    if (status == "已发送") {
                        alert("订单" + orderNo + "已发送");
                        is_up = true;
                        return false;
                    }

                    if (logisticsOrderNo == null) {
                        alert("运单号为空！");
                    }
                    orderList.push({ OrderNo: orderNo, LogisticsOrderNo: logisticsOrderNo, LogisticsName: logisticsName, LogisticsCode: logisticsCode });
                })

                if (is_up) {
                    return false;
                }
                if (orderList.length == 0) {
                    alert("请上传文件");
                    return false;
                }
                $("#orderNosLogisticsOrderNos").val(JSON.stringify(orderList));
                $("#orderForm").submit();
            })

        })


    </script>

}

<div class="row">
    <form id="fileForm" class="form-group" action='@Url.Action("UploadOrder", "Order")' method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="exampleInputFile">文件上传</label>
            <input type="file" name="uploadFile" accept="text/csv" id="uploadFile" />
        </div>
        <div class="form-group">
            <label for="imgTemplate">CSV模板</label>
            <p>订单号,运单号,物流公司,物流公司代码</p>
            <p>S2015060516274958278,YD0001,EMS,E01</p>
            <p><a href='@Url.Action("DownLoadLogistisc", "Order")'>下载模板</a></p>
        </div>
        <input type="hidden" value='@ViewBag.ConsignerId' name="ConsignerId" />
    </form>

    @{
        if (Model != null)
        {
        <table class="table table-bordered" id="tb_contact">
            <thead>
                <tr>
                    <td>订单编号</td>
                    <td>运单编号</td>
                    <td>物流公司</td>
                    <td>物流公司代码</td>
                    <td>状态</td>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    var status = item.Status >= Inovout.Kuajing.Models.ShipmentOrderStatus.Shipped ? "已发送" : "未发送";
                    <tr>
                        <td>@item.No</td>
                        <td>@item.LogisticsOrderNo</td>
                        <td>@item.LogisticsCompanyName</td>
                        <td>@item.LogisticsCompanyCode</td>
                        <td>@status</td>
                    </tr>
                }
            </tbody>
        </table>
        }
        else
        {
        <table class="table table-bordered">
            <thead>
                <tr>
                    <td>订单编号</td>
                    <td>运单编号</td>
                    <td>物流公司</td>
                    <td>物流公司代码</td>
                    <td>状态</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td colspan="5">无数据!</td>
                </tr>
            </tbody>
        </table>
        }
        
    
    }


    <form  id="orderForm" action='@Url.Action("SaveOrder", "Order")' method="post">
        <input name="orderNosLogisticsOrderNos" type="hidden" id="orderNosLogisticsOrderNos" />
        <input type="hidden" value='@ViewBag.ConsignerId' name="consigner" />
        <button type="button" id="uploadlogisticsInfo" class="btn btn-default">上传物流信息</button>
    </form>
</div>

